// @before-stub-for-debug-begin
#include <vector>
#include <string>
#include "commoncppproblem606.h"

using namespace std;
// @before-stub-for-debug-end

/*
 * @lc app=leetcode.cn id=606 lang=cpp
 *
 * [606] 根据二叉树创建字符串
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    string tree2str(TreeNode* t) {
        if(t == NULL)
            return "";
        string s = to_string(t->val);
        if(t->left)
            s += "(" + tree2str() + ")";
        else
            s += "()";
        if(t->right)
            s += "(" + tree2str() + ")";

        return s;
    }
};
// @lc code=end

